<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8" />
   
  <meta name="keywords" content="郑浩枫,周芳怡,咸鱼郑某的博客" />
   
  <meta name="description" content="咸鱼郑某的博客" />
  
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
  <title>
    针对nyato.com的爬虫 |  岛
  </title>
  <meta name="generator" content="hexo-theme-yilia-plus">
  
  <link rel="shortcut icon" href="/favicon.ico" />
  
  
<link rel="stylesheet" href="/css/main.css">

  
  <script src="https://cdn.jsdelivr.net/npm/pace-js@1.0.2/pace.min.js"></script>
  
  

  

<link rel="alternate" href="/atom.xml" title="岛" type="application/atom+xml">
</head>

</html>

<body>
  <div id="app">
    <main class="content">
      <section class="outer">
  <article id="post-www.nyato.com爬虫" class="article article-type-post" itemscope
  itemprop="blogPost" data-scroll-reveal>

  <div class="article-inner">
    
    <header class="article-header">
       
<h1 class="article-title sea-center" style="border-left:0" itemprop="name">
  针对nyato.com的爬虫
</h1>
  

    </header>
    

    
    <div class="article-meta">
      <a href="/2020/%E9%92%88%E5%AF%B9nyato.com%E7%9A%84%E7%88%AC%E8%99%AB/" class="article-date">
  <time datetime="2020-04-05T06:21:37.000Z" itemprop="datePublished">2020-04-05</time>
</a>
      
  <div class="article-category">
    <a class="article-category-link" href="/categories/%E6%8A%80%E6%9C%AF/">技术</a>
  </div>

      
      
<div class="word_count">
    <span class="post-time">
        <span class="post-meta-item-icon">
            <i class="ri-quill-pen-line"></i>
            <span class="post-meta-item-text"> 字数统计:</span>
            <span class="post-count">3.5k字</span>
        </span>
    </span>

    <span class="post-time">
        &nbsp; | &nbsp;
        <span class="post-meta-item-icon">
            <i class="ri-book-open-line"></i>
            <span class="post-meta-item-text"> 阅读时长≈</span>
            <span class="post-count">19分钟</span>
        </span>
    </span>
</div>

      
    </div>
    

    
    
    <div class="tocbot"></div>





    

    
    <div class="article-entry" itemprop="articleBody">
      
      

      
      <h3 id="针对nyato-com的爬虫"><a href="#针对nyato-com的爬虫" class="headerlink" title="针对nyato.com的爬虫"></a>针对nyato.com的爬虫</h3><span id="more"></span>
<p>有一说一，是真的好看。</p>
<p><img src="https://web-1253780623.cos.ap-shanghai.myqcloud.com/zhf-blog/images/%E9%92%88%E5%AF%B9nyato.com%E7%9A%84%E7%88%AC%E8%99%AB/%E7%BD%91%E7%AB%99%E9%A6%96%E9%A1%B5.png" alt="网站首页"></p>
<p>这么好看的妹子不加进我的<a href="https://zhfhz.gitee.io/2020/younger_sister_img/">younger_sister_img（小姐姐图片库）</a>岂不是天理不容？</p>
<p>于是开始写爬虫。</p>
<h3 id="先来分析网页"><a href="#先来分析网页" class="headerlink" title="先来分析网页"></a>先来分析网页</h3><p>看网页一共有5页<br><img src="https://web-1253780623.cos.ap-shanghai.myqcloud.com/zhf-blog/images/%E9%92%88%E5%AF%B9nyato.com%E7%9A%84%E7%88%AC%E8%99%AB/%E4%B8%80%E5%85%B1%E6%9C%895%E9%A1%B5.png"></p>
<p>令人惊喜的是网站不是动态加载的，大大降低了我们的难度。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs plain">https:&#x2F;&#x2F;www.nyato.com&#x2F;index.php?app&#x3D;public&amp;mod&#x3D;Topic&amp;act&#x3D;index&amp;k&#x3D;%E7%BB%9D%E5%AF%B9%E9%A2%86%E5%9F%9F&amp;p&#x3D;1<br></code></pre></td></tr></table></figure>
<p>观察URL可以发现，每一页通过URL的<code>p=</code>来决定</p>
<p>那么遍历这5页的代码就很好写了</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs plain">for num in range(1, 6):  <br>    page_url &#x3D; &quot;https:&#x2F;&#x2F;www.nyato.com&#x2F;index.php?app&#x3D;public&amp;mod&#x3D;Topic&amp;act&#x3D;index&amp;k&#x3D;%E7%BB%9D%E5%AF%B9%E9%A2%86%E5%9F%9F&amp;p&#x3D;&quot; + str(1)  <br>    print(page_url)<br></code></pre></td></tr></table></figure>
<p>输出结果：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><code class="hljs plain">https:&#x2F;&#x2F;www.nyato.com&#x2F;index.php?app&#x3D;public&amp;mod&#x3D;Topic&amp;act&#x3D;index&amp;k&#x3D;%E7%BB%9D%E5%AF%B9%E9%A2%86%E5%9F%9F&amp;p&#x3D;1<br>https:&#x2F;&#x2F;www.nyato.com&#x2F;index.php?app&#x3D;public&amp;mod&#x3D;Topic&amp;act&#x3D;index&amp;k&#x3D;%E7%BB%9D%E5%AF%B9%E9%A2%86%E5%9F%9F&amp;p&#x3D;1<br>https:&#x2F;&#x2F;www.nyato.com&#x2F;index.php?app&#x3D;public&amp;mod&#x3D;Topic&amp;act&#x3D;index&amp;k&#x3D;%E7%BB%9D%E5%AF%B9%E9%A2%86%E5%9F%9F&amp;p&#x3D;1<br>https:&#x2F;&#x2F;www.nyato.com&#x2F;index.php?app&#x3D;public&amp;mod&#x3D;Topic&amp;act&#x3D;index&amp;k&#x3D;%E7%BB%9D%E5%AF%B9%E9%A2%86%E5%9F%9F&amp;p&#x3D;1<br>https:&#x2F;&#x2F;www.nyato.com&#x2F;index.php?app&#x3D;public&amp;mod&#x3D;Topic&amp;act&#x3D;index&amp;k&#x3D;%E7%BB%9D%E5%AF%B9%E9%A2%86%E5%9F%9F&amp;p&#x3D;1<br></code></pre></td></tr></table></figure>
<p>接下来继续观察网页,通过审查元素可以发现，图集的URL类似于：<code>https://www.nyato.com/forum/1045080</code><br><img src="https://web-1253780623.cos.ap-shanghai.myqcloud.com/zhf-blog/images/%E9%92%88%E5%AF%B9nyato.com%E7%9A%84%E7%88%AC%E8%99%AB/%E5%9B%BE%E9%9B%86%E5%AE%A1%E5%AF%9F%E5%85%83%E7%B4%A0.png"></p>
<h3 id="我们首先获取页面的HTML"><a href="#我们首先获取页面的HTML" class="headerlink" title="我们首先获取页面的HTML"></a>我们首先获取页面的HTML</h3><p>导入<code>requests</code>和 <code>bs4</code></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs plain">import requests  <br>from bs4 import BeautifulSoup<br></code></pre></td></tr></table></figure>
<p>接着用<code> requests.get()</code>发送<code>Get</code>请求，通过<code>BeautifulSoup(,&quot;html.parser&quot;)</code>来解析获取到的HTML</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><code class="hljs plain">page_url &#x3D; &quot;https:&#x2F;&#x2F;www.nyato.com&#x2F;index.php?app&#x3D;public&amp;mod&#x3D;Topic&amp;act&#x3D;index&amp;k&#x3D;%E7%BB%9D%E5%AF%B9%E9%A2%86%E5%9F%9F&amp;p&#x3D;&quot; + str(1)  <br>response &#x3D; requests.get(page_url)  <br>response.encoding &#x3D; &#39;utf-8&#39;  <br>html &#x3D; response.text  <br>soup &#x3D; BeautifulSoup(html, &quot;html.parser&quot;)  <br>print(soup)<br></code></pre></td></tr></table></figure>
<p>输出结果：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><code class="hljs plain">&lt;!DOCTYPE html&gt;<br><br>&lt;html&gt;<br>&lt;head&gt;<br>&lt;meta charset&#x3D;&quot;utf-8&quot;&#x2F;&gt;<br>&lt;title&gt;绝对领域&lt;&#x2F;title&gt;<br>&lt;meta content&#x3D;&quot;绝对领域&quot; name&#x3D;&quot;keywords&quot;&#x2F;&gt;<br>&lt;meta content&#x3D;&quot;--#Cosplay##漫展返图##Lolita##cos正片##深圳漫展##COS妆##cosplay正片##COS场照##coser##COS##私房##洛丽塔##萌妹##lolita私影##自拍##扩列##宅舞##女装大佬##水着##旗袍##ps后期##求摄影，求后勤##兽耳##裸足##足控福利##兔女郎##御姐##制服##巨乳##爱coser##爱宕##黑丝##腿控福利##足控##欧派##福利姬##摄影##JK##漫展##漫展约拍##lolita装扮##萌系小姐姐##秋名山老司机##场照##jk日常##JK制服##求约展##正片##求助##招募##百合##福利##男装大佬##绝对领域##泳装##双马尾##萝莉##白丝#&quot; name&#x3D;&quot;description&quot;&#x2F;&gt;<br>&lt;link href&#x3D;&quot;&#x2F;&#x2F;static.nyato.cn&#x2F;image&#x2F;favicon.ico?v&#x3D;20200326&quot; rel&#x3D;&quot;shortcut icon&quot; type&#x3D;&quot;image&#x2F;x-icon&quot;&#x2F;&gt;<br>&lt;link href&#x3D;&quot;&#x2F;&#x2F;static.nyato.cn&#x2F;ui&#x2F;jqueryui.css?v&#x3D;20200326&quot; rel&#x3D;&quot;stylesheet&quot; type&#x3D;&quot;text&#x2F;css&quot;&#x2F;&gt;<br>&lt;link href&#x3D;&quot;&#x2F;&#x2F;static.nyato.cn&#x2F;js&#x2F;tbox&#x2F;box.css?20110820&quot; rel&#x3D;&quot;stylesheet&quot; type&#x3D;&quot;text&#x2F;css&quot;&#x2F;&gt;<br>&lt;link href&#x3D;&quot;&#x2F;&#x2F;static.nyato.cn&#x2F;css&#x2F;module.css?v&#x3D;20200326&quot; rel&#x3D;&quot;stylesheet&quot; type&#x3D;&quot;text&#x2F;css&quot;&#x2F;&gt;<br>&lt;link href&#x3D;&quot;&#x2F;&#x2F;static.nyato.cn&#x2F;css&#x2F;style.css?v&#x3D;20200326&quot; rel&#x3D;&quot;stylesheet&quot; type&#x3D;&quot;text&#x2F;css&quot;&#x2F;&gt;<br>&lt;link href&#x3D;&quot;&#x2F;&#x2F;static.nyato.cn&#x2F;v4&#x2F;css&#x2F;style.css?v&#x3D;20200326&quot; rel&#x3D;&quot;stylesheet&quot; type&#x3D;&quot;text&#x2F;css&quot;&#x2F;&gt;<br>&lt;link href&#x3D;&quot;&#x2F;&#x2F;static.nyato.cn&#x2F;v4&#x2F;css&#x2F;main.css?v&#x3D;20200326&quot; rel&#x3D;&quot;stylesheet&quot; type&#x3D;&quot;text&#x2F;css&quot;&#x2F;&gt;<br>&lt;link href&#x3D;&quot;&#x2F;&#x2F;static.nyato.cn&#x2F;v4_3&#x2F;css&#x2F;style.css?v&#x3D;20200326&quot; rel&#x3D;&quot;stylesheet&quot; type&#x3D;&quot;text&#x2F;css&quot;&#x2F;&gt;<br>&lt;link href&#x3D;&quot;&#x2F;&#x2F;static.nyato.cn&#x2F;v4_3&#x2F;css&#x2F;main.css?v&#x3D;202003261&quot; rel&#x3D;&quot;stylesheet&quot; type&#x3D;&quot;text&#x2F;css&quot;&#x2F;&gt;<br></code></pre></td></tr></table></figure>
<p>太多只复制一部分</p>
<p>接着通过<code>soup.find_all(&#39;a&#39;)</code>和获取所有的<code>&lt;a&gt;</code>标签</p>
<p>遍历所有<code>&lt;a&gt;</code>标签，并通过<code>.get(&#39;href&#39;)</code>获取标签中的链接</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs plain">a_link_all &#x3D; soup.find_all(&#39;a&#39;)  <br>for item in a_link_all:  <br>    print(item.get(&#39;href&#39;))<br></code></pre></td></tr></table></figure>
<p>输出结果：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><code class="hljs plain">https:&#x2F;&#x2F;www.nyato.com<br>https:&#x2F;&#x2F;www.nyato.com<br>https:&#x2F;&#x2F;www.nyato.com&#x2F;manzhan&#x2F;<br>https:&#x2F;&#x2F;www.nyato.com&#x2F;forum&#x2F;<br>#<br>https:&#x2F;&#x2F;www.nyato.com&#x2F;about&#x2F;nyato_app<br>https:&#x2F;&#x2F;www.nyato.com&#x2F;places&#x2F;<br>https:&#x2F;&#x2F;www.nyato.com&#x2F;group&#x2F;<br>https:&#x2F;&#x2F;www.nyato.com&#x2F;works&#x2F;<br>javascript:void(0)<br>javascript:void(0)<br>https:&#x2F;&#x2F;www.nyato.com&#x2F;register<br>https:&#x2F;&#x2F;www.nyato.com&#x2F;index.php?app&#x3D;public&amp;mod&#x3D;Passport&amp;act&#x3D;findPassword<br>https:&#x2F;&#x2F;www.nyato.com&#x2F;index.php?app&#x3D;public&amp;mod&#x3D;Widget&amp;act&#x3D;displayAddons&amp;type&#x3D;sina&amp;addon&#x3D;Login&amp;hook&#x3D;login_sync_other<br>https:&#x2F;&#x2F;www.nyato.com&#x2F;index.php?app&#x3D;public&amp;mod&#x3D;Widget&amp;act&#x3D;displayAddons&amp;type&#x3D;qzone&amp;addon&#x3D;Login&amp;hook&#x3D;login_sync_other<br>https:&#x2F;&#x2F;www.nyato.com&#x2F;index.php?app&#x3D;public&amp;mod&#x3D;Widget&amp;act&#x3D;displayAddons&amp;type&#x3D;wechat&amp;addon&#x3D;Login&amp;hook&#x3D;login_sync_other<br>https:&#x2F;&#x2F;www.nyato.com&#x2F;register<br>None<br>None<br>None<br>#<br>#<br>#<br>#<br>https:&#x2F;&#x2F;www.nyato.com&#x2F;Topic&#x2F;绝对领域<br>https:&#x2F;&#x2F;www.nyato.com&#x2F;Topic&#x2F;绝对领域?type&#x3D;1<br>https:&#x2F;&#x2F;www.nyato.com&#x2F;Topic&#x2F;绝对领域?type&#x3D;2<br>https:&#x2F;&#x2F;www.nyato.com&#x2F;Topic&#x2F;绝对领域?type&#x3D;3<br>https:&#x2F;&#x2F;www.nyato.com&#x2F;user&#x2F;392620<br></code></pre></td></tr></table></figure>
<p>太多只复制一部分</p>
<p>可以看到，输出的结果乱，观察发现，图集的URL前面都是<br><code>https://www.nyato.com/forum/</code>把它和获取到的URL进行比较<br>通过<code>.find(&quot;&quot;)</code>来查询URL中有没有我们想要的</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><code class="hljs plain">for item in a_link_all:  <br>    page_url &#x3D; item.get(&#39;href&#39;)  <br>    if str(page_url).find(&quot;https:&#x2F;&#x2F;www.nyato.com&#x2F;forum&#x2F;&quot;) !&#x3D; -1:  <br>        print(page_url)<br></code></pre></td></tr></table></figure>
<p>输出结果：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><code class="hljs plain">https:&#x2F;&#x2F;www.nyato.com&#x2F;forum&#x2F;<br>https:&#x2F;&#x2F;www.nyato.com&#x2F;forum&#x2F;1575950<br>https:&#x2F;&#x2F;www.nyato.com&#x2F;forum&#x2F;1575950<br>https:&#x2F;&#x2F;www.nyato.com&#x2F;forum&#x2F;1045080<br>https:&#x2F;&#x2F;www.nyato.com&#x2F;forum&#x2F;1045080<br>https:&#x2F;&#x2F;www.nyato.com&#x2F;forum&#x2F;892522<br>https:&#x2F;&#x2F;www.nyato.com&#x2F;forum&#x2F;892522<br>https:&#x2F;&#x2F;www.nyato.com&#x2F;forum&#x2F;876262<br>https:&#x2F;&#x2F;www.nyato.com&#x2F;forum&#x2F;876262<br>https:&#x2F;&#x2F;www.nyato.com&#x2F;forum&#x2F;873103<br>https:&#x2F;&#x2F;www.nyato.com&#x2F;forum&#x2F;873103<br>https:&#x2F;&#x2F;www.nyato.com&#x2F;forum&#x2F;863490<br>https:&#x2F;&#x2F;www.nyato.com&#x2F;forum&#x2F;863490<br>https:&#x2F;&#x2F;www.nyato.com&#x2F;forum&#x2F;861600<br>https:&#x2F;&#x2F;www.nyato.com&#x2F;forum&#x2F;861600<br>https:&#x2F;&#x2F;www.nyato.com&#x2F;forum&#x2F;858398<br>https:&#x2F;&#x2F;www.nyato.com&#x2F;forum&#x2F;858398<br>https:&#x2F;&#x2F;www.nyato.com&#x2F;forum&#x2F;848410<br>https:&#x2F;&#x2F;www.nyato.com&#x2F;forum&#x2F;848410<br>https:&#x2F;&#x2F;www.nyato.com&#x2F;forum&#x2F;847528<br>https:&#x2F;&#x2F;www.nyato.com&#x2F;forum&#x2F;847528<br></code></pre></td></tr></table></figure>
<p>发现同一个URL重复了两次。<br>所以我们把获取到的URL放进数组中，在获取到下个URL后，和数组中已存在的进行比较，如果重复，就不加入数组。</p>
<p>提前初始化好数组，如果数组中不存在相同的，通过<code>append()</code>添加进数组</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><code class="hljs plain">page_url_list &#x3D; [] #初始化链接数组  <br>for item in a_link_all:  <br>    page_url &#x3D; item.get(&#39;href&#39;)  <br>    if str(page_url).find(&quot;https:&#x2F;&#x2F;www.nyato.com&#x2F;forum&#x2F;&quot;) !&#x3D; -1:  <br>        if not(page_url in page_url_list):  <br>            page_url_list.append(page_url)<br></code></pre></td></tr></table></figure>
<p>这样我们就获得了所以图集的URL</p>
<p>输出看看</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs plain">for item2 in page_url_list:  <br>    print(item2)<br></code></pre></td></tr></table></figure>

<p>输出结果：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><code class="hljs plain">https:&#x2F;&#x2F;www.nyato.com&#x2F;forum&#x2F;<br>https:&#x2F;&#x2F;www.nyato.com&#x2F;forum&#x2F;668122<br>https:&#x2F;&#x2F;www.nyato.com&#x2F;forum&#x2F;633482<br>https:&#x2F;&#x2F;www.nyato.com&#x2F;forum&#x2F;1497353<br>https:&#x2F;&#x2F;www.nyato.com&#x2F;forum&#x2F;59186<br>https:&#x2F;&#x2F;www.nyato.com&#x2F;forum&#x2F;1696607<br></code></pre></td></tr></table></figure>
<h3 id="接下来就是进入图集获取所有的图片URL"><a href="#接下来就是进入图集获取所有的图片URL" class="headerlink" title="接下来就是进入图集获取所有的图片URL"></a>接下来就是进入图集获取所有的图片URL</h3><p>我们要排除掉<code>https://www.nyato.com/forum/</code>这一页</p>
<p>和上面方法一样获取到HTML后再获取<code>&lt;img&gt;</code>标签中的<code>src</code>就好了</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><code class="hljs plain">for item2 in page_url_list:  <br>    if item2 !&#x3D; &quot;https:&#x2F;&#x2F;www.nyato.com&#x2F;forum&#x2F;&quot;:  # 排除第一页  <br>	response &#x3D; requests.get(item2)  # 发送请求  <br>	response.encoding &#x3D; &#39;utf-8&#39;  <br>	html &#x3D; response.text  <br>    soup &#x3D; BeautifulSoup(html, &quot;html.parser&quot;)  <br>    img_link_all &#x3D; soup.find_all(&#39;img&#39;)  <br>    img_unm &#x3D; 0 # 图片编号初始化  <br>    img_group &#x3D; img_group + 1 # 图集编号自增  <br>		for item3 in img_link_all:  <br>            img_url &#x3D; item3.get(&#39;src&#39;)<br></code></pre></td></tr></table></figure>
<p>结果应该是这样的</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><code class="hljs plain">&#x2F;img.nyato.com&#x2F;data&#x2F;upload&#x2F;avatar&#x2F;2019&#x2F;1025&#x2F;14&#x2F;5db297d8d7c24.jpg!50x50cut<br>&#x2F;&#x2F;img.nyato.com&#x2F;data&#x2F;upload&#x2F;avatar&#x2F;2020&#x2F;0331&#x2F;19&#x2F;5e832e9f75d1e.jpg!50x50cut<br>&#x2F;&#x2F;img.nyato.com&#x2F;data&#x2F;upload&#x2F;avatar&#x2F;2020&#x2F;0120&#x2F;18&#x2F;5e257d894f0cf.png!50x50cut<br>&#x2F;&#x2F;img.nyato.com&#x2F;data&#x2F;upload&#x2F;avatar&#x2F;2018&#x2F;0718&#x2F;15&#x2F;5b4ef31ea9ae9.png!50x50cut<br>&#x2F;&#x2F;static.nyato.cn&#x2F;v4_3&#x2F;img&#x2F;new_f_logo.png<br>&#x2F;&#x2F;static.nyato.cn&#x2F;expo-image&#x2F;style&#x2F;ico-ww.png<br>&#x2F;&#x2F;static.nyato.cn&#x2F;expo-image&#x2F;style&#x2F;ico-ga.png<br>https:&#x2F;&#x2F;img.nyato.com&#x2F;data&#x2F;upload&#x2F;2018&#x2F;0514&#x2F;08&#x2F;5af8d2ea4b24d.jpg!autoxauto<br>https:&#x2F;&#x2F;img.nyato.com&#x2F;data&#x2F;upload&#x2F;2018&#x2F;0514&#x2F;08&#x2F;5af8d2ee8a90f.jpg!autoxauto<br>https:&#x2F;&#x2F;img.nyato.com&#x2F;data&#x2F;upload&#x2F;2018&#x2F;0514&#x2F;08&#x2F;5af8d2f2d80eb.jpg!autoxauto<br>https:&#x2F;&#x2F;img.nyato.com&#x2F;data&#x2F;upload&#x2F;2018&#x2F;0514&#x2F;08&#x2F;5af8d2f6a104e.jpg!autoxauto<br>https:&#x2F;&#x2F;img.nyato.com&#x2F;data&#x2F;upload&#x2F;2018&#x2F;0514&#x2F;08&#x2F;5af8d2faa9c27.jpg!autoxauto<br>https:&#x2F;&#x2F;img.nyato.com&#x2F;data&#x2F;upload&#x2F;2018&#x2F;0514&#x2F;08&#x2F;5af8d2febd33d.jpg!autoxauto<br>https:&#x2F;&#x2F;img.nyato.com&#x2F;data&#x2F;upload&#x2F;2018&#x2F;0514&#x2F;08&#x2F;5af8d3026a740.jpg!autoxauto<br>https:&#x2F;&#x2F;img.nyato.com&#x2F;data&#x2F;upload&#x2F;2018&#x2F;0514&#x2F;08&#x2F;5af8d305e8701.jpg!autoxauto<br>https:&#x2F;&#x2F;img.nyato.com&#x2F;data&#x2F;upload&#x2F;2018&#x2F;0514&#x2F;08&#x2F;5af8d30a8e48d.jpg!autoxauto<br>https:&#x2F;&#x2F;www.nyato.com&#x2F;apps&#x2F;index&#x2F;_static&#x2F;Street&#x2F;img&#x2F;phone_code.png<br>&#x2F;&#x2F;img.nyato.com&#x2F;data&#x2F;upload&#x2F;avatar&#x2F;0b&#x2F;dc&#x2F;88&#x2F;original.jpg!100x100cut<br>&#x2F;&#x2F;img.nyato.com&#x2F;data&#x2F;upload&#x2F;avatar&#x2F;2019&#x2F;1013&#x2F;10&#x2F;5da28c0ab3483.png!50x50cut<br>&#x2F;&#x2F;img.nyato.com&#x2F;data&#x2F;upload&#x2F;avatar&#x2F;2020&#x2F;0331&#x2F;19&#x2F;5e832e9f75d1e.jpg!50x50cut<br>&#x2F;&#x2F;img.nyato.com&#x2F;data&#x2F;upload&#x2F;avatar&#x2F;2020&#x2F;0404&#x2F;00&#x2F;5e87664d72c56.jpg!50x50cut<br></code></pre></td></tr></table></figure>

<p>通过观察发现，类似</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs plain">https:&#x2F;&#x2F;img.nyato.com&#x2F;data&#x2F;upload&#x2F;2018&#x2F;0514&#x2F;08&#x2F;5af8d2faa9c27.jpg!autoxauto<br></code></pre></td></tr></table></figure>
<p>这样的才是我们要的图片<br><img src="https://web-1253780623.cos.ap-shanghai.myqcloud.com/zhf-blog/images/%E9%92%88%E5%AF%B9nyato.com%E7%9A%84%E7%88%AC%E8%99%AB/%E5%B0%8F%E5%A7%90%E5%A7%90%E5%9B%BE%E7%89%87.png" alt="小姐姐图片"></p>
<p>那么同理，我们过滤参数</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><code class="hljs plain"># 排除404和乱七八糟的图  <br>if str(img_url).find(&quot;https:&#x2F;&#x2F;img.nyato.com&#x2F;data&#x2F;upload&#x2F;image&quot;) !&#x3D; -1 and str(img_url) !&#x3D; &quot;https:&#x2F;&#x2F;img.nyato.com&#x2F;data&#x2F;upload&#x2F;image&#x2F;20190306&#x2F;1551841494987077.png&quot;:  <br>    down_url &#x3D; str(img_url).replace(&quot;!autoxauto&quot;, &quot;&quot;)  # 最终下载的URL  <br>	print(down_url)<br></code></pre></td></tr></table></figure>
<p>这样就可以得到我们要的东西了</p>
<p>输出结果</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><code class="hljs plain">https:&#x2F;&#x2F;img.nyato.com&#x2F;data&#x2F;upload&#x2F;image&#x2F;20190410&#x2F;1554861703839125.jpg<br>https:&#x2F;&#x2F;img.nyato.com&#x2F;data&#x2F;upload&#x2F;image&#x2F;20190410&#x2F;1554861703961321.jpg<br>https:&#x2F;&#x2F;img.nyato.com&#x2F;data&#x2F;upload&#x2F;image&#x2F;20190410&#x2F;1554861703348718.jpg<br>https:&#x2F;&#x2F;img.nyato.com&#x2F;data&#x2F;upload&#x2F;image&#x2F;20190410&#x2F;1554861703517692.jpg<br>https:&#x2F;&#x2F;img.nyato.com&#x2F;data&#x2F;upload&#x2F;image&#x2F;20190410&#x2F;1554861704425800.jpg<br>https:&#x2F;&#x2F;img.nyato.com&#x2F;data&#x2F;upload&#x2F;image&#x2F;20190410&#x2F;1554861704408566.jpg<br>https:&#x2F;&#x2F;img.nyato.com&#x2F;data&#x2F;upload&#x2F;image&#x2F;20190410&#x2F;1554861704733334.jpg<br>https:&#x2F;&#x2F;img.nyato.com&#x2F;data&#x2F;upload&#x2F;image&#x2F;20181229&#x2F;1546052590584934.jpg<br>https:&#x2F;&#x2F;img.nyato.com&#x2F;data&#x2F;upload&#x2F;image&#x2F;20181229&#x2F;1546052590278073.jpg<br>https:&#x2F;&#x2F;img.nyato.com&#x2F;data&#x2F;upload&#x2F;image&#x2F;20181229&#x2F;1546052590610244.jpg<br>https:&#x2F;&#x2F;img.nyato.com&#x2F;data&#x2F;upload&#x2F;image&#x2F;20181229&#x2F;1546052590647973.jpg<br>https:&#x2F;&#x2F;img.nyato.com&#x2F;data&#x2F;upload&#x2F;image&#x2F;20181229&#x2F;1546052590464936.jpg<br>https:&#x2F;&#x2F;img.nyato.com&#x2F;data&#x2F;upload&#x2F;image&#x2F;20181229&#x2F;1546052590814772.jpg<br>https:&#x2F;&#x2F;img.nyato.com&#x2F;data&#x2F;upload&#x2F;image&#x2F;20181229&#x2F;1546052590257442.jpg<br>https:&#x2F;&#x2F;img.nyato.com&#x2F;data&#x2F;upload&#x2F;image&#x2F;20181229&#x2F;1546052590521444.jpg<br>https:&#x2F;&#x2F;img.nyato.com&#x2F;data&#x2F;upload&#x2F;image&#x2F;20181229&#x2F;1546052590789982.jpg<br></code></pre></td></tr></table></figure>
<p>太多就不复制了</p>
<p>有些图片虽然能获取到URL，但是实际上是不存在的，所以我们加一个判断</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs plain">html_head &#x3D; requests.head(down_url)  # 用head方法去请求资源头  <br>re_code &#x3D; html_head.status_code  # 返回请求值<br>if re_code &#x3D;&#x3D; 200:  # 如果图片存在  <br></code></pre></td></tr></table></figure>
<p>最后就是美滋滋的开始下载了</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs plain">urllib.request.urlretrieve(img_url, img_name)  # 下载<br></code></pre></td></tr></table></figure>
<p>一般我会对图片进行编号，所以会多加几步，这里就不多说了</p>
<h3 id="完整代码"><a href="#完整代码" class="headerlink" title="完整代码"></a>完整代码</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br></pre></td><td class="code"><pre><code class="hljs plain">import requests  <br>from bs4 import BeautifulSoup  <br>import urllib.request  <br>img_group &#x3D; 25717 #初始图集编号  <br>for num in range(1, 6):  <br>    page_url &#x3D; &quot;https:&#x2F;&#x2F;www.nyato.com&#x2F;index.php?app&#x3D;public&amp;mod&#x3D;Topic&amp;act&#x3D;index&amp;k&#x3D;%E7%BB%9D%E5%AF%B9%E9%A2%86%E5%9F%9F&amp;p&#x3D;&quot; + str(num)  <br>    response &#x3D; requests.get(page_url)  <br>    response.encoding &#x3D; &#39;utf-8&#39;  <br>  html &#x3D; response.text  <br>    soup &#x3D; BeautifulSoup(html, &quot;html.parser&quot;)  <br>    a_link_all &#x3D; soup.find_all(&#39;a&#39;)  <br>    page_url_list &#x3D; [] #初始化链接数组  <br>  for item in a_link_all:  <br>        page_url &#x3D; item.get(&#39;href&#39;)  <br>        if str(page_url).find(&quot;https:&#x2F;&#x2F;www.nyato.com&#x2F;forum&#x2F;&quot;) !&#x3D; -1:  <br>            if not(page_url in page_url_list):  <br>                page_url_list.append(page_url)  <br>    #开始遍历所有图集  <br>  for item2 in page_url_list:  <br>        if item2 !&#x3D; &quot;https:&#x2F;&#x2F;www.nyato.com&#x2F;forum&#x2F;&quot;: #排除第一页  <br>  response &#x3D; requests.get(item2) #发送请求  <br>  response.encoding &#x3D; &#39;utf-8&#39;  <br>  html &#x3D; response.text  <br>            soup &#x3D; BeautifulSoup(html, &quot;html.parser&quot;)  <br>            img_link_all &#x3D; soup.find_all(&#39;img&#39;)  <br>            img_unm &#x3D; 0 # 图片编号初始化  <br>  img_group &#x3D; img_group +1 #图集编号自增  <br>  for item3 in img_link_all:  <br>               img_url &#x3D; item3.get(&#39;src&#39;)  <br>               # 排除404和乱七八糟的图  <br>  if str(img_url).find(&quot;https:&#x2F;&#x2F;img.nyato.com&#x2F;data&#x2F;upload&#x2F;image&quot;) !&#x3D; -1 and str(img_url) !&#x3D; &quot;https:&#x2F;&#x2F;img.nyato.com&#x2F;data&#x2F;upload&#x2F;image&#x2F;20190306&#x2F;1551841494987077.png&quot;:  <br>                   down_url &#x3D; str(img_url).replace(&quot;!autoxauto&quot;,&quot;&quot;) #最终下载的URL  <br>  html_head &#x3D; requests.head(down_url)  # 用head方法去请求资源头  <br>  re_code &#x3D; html_head.status_code  # 返回请求值  <br>  if re_code &#x3D;&#x3D; 200:  # 如果图片存在  <br>  img_unm &#x3D; img_unm + 1 #图片编号自增  <br>  img_name &#x3D; str(img_group) + &quot;_&quot; + str(img_unm) + &quot;.jpg&quot; #图片名称  <br>  urllib.request.urlretrieve(img_url, img_name)  # 下载  <br>  if img_unm !&#x3D; 0:  <br>                   txt &#x3D; &quot;&#123;\&quot;&quot; + str(img_group) + &quot;\&quot;:\&quot;&quot; + str(img_unm) + &quot;\&quot;&#125;&quot;  <br>  print(txt)  <br>                   result2txt &#x3D; str(txt)  #data是前面运行出的数据，先将其转为字符串才能写入  <br>  with open(&#39;结果.txt&#39;, &#39;a&#39;) as file_handle:  # .txt可以不自己新建,代码会自动新建  <br>  file_handle.write(result2txt)  # 写入  <br>  file_handle.write(&#39;\n&#39;)  # 有时放在循环里面需要自动转行，不然会覆盖上一条数据<br></code></pre></td></tr></table></figure>
<h3 id="最后结果"><a href="#最后结果" class="headerlink" title="最后结果"></a>最后结果</h3><p><img src="https://web-1253780623.cos.ap-shanghai.myqcloud.com/zhf-blog/images/%E9%92%88%E5%AF%B9nyato.com%E7%9A%84%E7%88%AC%E8%99%AB/%E7%BB%93%E6%9E%9C.png" alt="最后结果"><br>才700张图片。。有点少啊</p>
<h3 id="OVER"><a href="#OVER" class="headerlink" title="OVER"></a>OVER</h3><p>在写爬虫的时候，发现大部分图片都是由ID叫“不来点妹汁吗”的用户发的<br>所以。。。🙈</p>

      
      <!-- reward -->
      
      <div id="reward-btn">
        打赏
      </div>
      
    </div>
    
    
      <!-- copyright -->
      
        <div class="declare">
          <ul class="post-copyright">
            <li>
              <i class="ri-copyright-line"></i>
              <strong>版权声明： </strong s>
              本博客所有文章除特别声明外，均采用 <a href="https://www.apache.org/licenses/LICENSE-2.0.html" rel="external nofollow"
                target="_blank">Apache License 2.0</a> 许可协议。转载请注明出处！
            </li>
          </ul>
        </div>
        
    <footer class="article-footer">
      
          
<div class="share-btn">
      <span class="share-sns share-outer">
        <i class="ri-share-forward-line"></i>
        分享
      </span>
      <div class="share-wrap">
        <i class="arrow"></i>
        <div class="share-icons">
          
          <a class="weibo share-sns" href="javascript:;" data-type="weibo">
            <i class="ri-weibo-fill"></i>
          </a>
          <a class="weixin share-sns wxFab" href="javascript:;" data-type="weixin">
            <i class="ri-wechat-fill"></i>
          </a>
          <a class="qq share-sns" href="javascript:;" data-type="qq">
            <i class="ri-qq-fill"></i>
          </a>
          <a class="douban share-sns" href="javascript:;" data-type="douban">
            <i class="ri-douban-line"></i>
          </a>
          <!-- <a class="qzone share-sns" href="javascript:;" data-type="qzone">
            <i class="icon icon-qzone"></i>
          </a> -->
          
          <a class="facebook share-sns" href="javascript:;" data-type="facebook">
            <i class="ri-facebook-circle-fill"></i>
          </a>
          <a class="twitter share-sns" href="javascript:;" data-type="twitter">
            <i class="ri-twitter-fill"></i>
          </a>
          <a class="google share-sns" href="javascript:;" data-type="google">
            <i class="ri-google-fill"></i>
          </a>
        </div>
      </div>
</div>

<div class="wx-share-modal">
    <a class="modal-close" href="javascript:;"><i class="ri-close-circle-line"></i></a>
    <p>扫一扫，分享到微信</p>
    <div class="wx-qrcode">
      <img src="//api.qrserver.com/v1/create-qr-code/?size=150x150&data=https://zhfhz.gitee.io/2020/%E9%92%88%E5%AF%B9nyato.com%E7%9A%84%E7%88%AC%E8%99%AB/" alt="微信分享二维码">
    </div>
</div>

<div id="share-mask"></div>
      
      
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/%E6%8A%80%E6%9C%AF/" rel="tag">技术</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/%E7%88%AC%E8%99%AB/" rel="tag">爬虫</a></li></ul>


    </footer>

  </div>

  
  
  <nav class="article-nav">
    
      <a href="/2020/%E8%AF%95%E7%8E%A9%E4%BA%86%E4%B8%80%E4%B8%8B%E8%BF%B7%E4%BD%A0%E4%B8%96%E7%95%8C/" class="article-nav-link">
        <strong class="article-nav-caption">上一篇</strong>
        <div class="article-nav-title">
          
            试玩了一下迷你世界
          
        </div>
      </a>
    
    
      <a href="/2020/Hexo%E8%A7%86%E9%A2%91%E6%92%AD%E6%94%BE/" class="article-nav-link">
        <strong class="article-nav-caption">下一篇</strong>
        <div class="article-nav-title">Hexo视频播放</div>
      </a>
    
  </nav>


  

  
  
<!-- valine评论 -->
<div id="vcomments-box">
    <div id="vcomments">
    </div>
</div>
<script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
<script src='https://cdn.jsdelivr.net/npm/valine@1.3.10/dist/Valine.min.js'></script>
<script>
    new Valine({
        el: '#vcomments',
        app_id: 'QExPaN3yEdYGXDLijnPKdTc8-MdYXbMMI',
        app_key: 'kyQzz6yRJkdRHcMm0tpOvSYY',
        path: window.location.pathname,
        notify: 'true',
        verify: 'false',
        avatar: 'mp',
        placeholder: '给我的文章加点评论吧~',
        recordIP: true
    });
    const infoEle = document.querySelector('#vcomments .info');
    if (infoEle && infoEle.childNodes && infoEle.childNodes.length > 0) {
        infoEle.childNodes.forEach(function (item) {
            item.parentNode.removeChild(item);
        });
    }
</script>
<style>
    #vcomments-box {
        padding: 5px 30px;
    }

    @media screen and (max-width: 800px) {
        #vcomments-box {
            padding: 5px 0px;
        }
    }

    #vcomments-box #vcomments {
        background-color: #fff;
    }

    .v .vlist .vcard .vh {
        padding-right: 20px;
    }

    .v .vlist .vcard {
        padding-left: 10px;
    }
</style>

  

  
  
  

</article>
</section>
      <footer class="footer">
  <div class="outer">
    <ul class="list-inline">
      <li>
        &copy;
        2020-2021
        ZHF
      </li>
      <li>
        
        Powered by
        
        
        <a href="https://hexo.io" target="_blank">Hexo</a> Theme <a href="https://github.com/Shen-Yu/hexo-theme-ayer" target="_blank">Ayer</a>
        
      </li>
    </ul>
    <ul class="list-inline">
      <li>
        
        
        <span>
  <i>PV:<span id="busuanzi_value_page_pv"></span></i>
  <i>UV:<span id="busuanzi_value_site_uv"></span></i>
</span>
        
      </li>
      
      <li>
        <!-- cnzz统计 -->
        
        <script type="text/javascript" src=''></script>
        
      </li>
    </ul>
  </div>
</footer>
      <div class="to_top">
        <div class="totop" id="totop">
  <i class="ri-arrow-up-line"></i>
</div>
      </div>
    </main>
    <aside class="sidebar">
      <button class="navbar-toggle"></button>
<nav class="navbar">
  
  <div class="logo">
    <a href="/"><img src="/images/ayer-side.svg" alt="岛"></a>
  </div>
  
  <ul class="nav nav-main">
    
    <li class="nav-item">
      <a class="nav-item-link" href="/">主页</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/archives">归档</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/categories">分类</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/tags">标签</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/tags/%E6%97%85%E8%A1%8C/">旅行</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" target="_blank" rel="noopener" href="https://500px.me/ZHFHZ">摄影</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/2019/about">关于我</a>
    </li>
    
  </ul>
</nav>
<nav class="navbar navbar-bottom">
  <ul class="nav">
    <li class="nav-item">
      
      <a class="nav-item-link nav-item-search"  title="Search">
        <i class="ri-search-line"></i>
      </a>
      
      
      <a class="nav-item-link" target="_blank" href="/atom.xml" title="RSS Feed">
        <i class="ri-rss-line"></i>
      </a>
      
    </li>
  </ul>
</nav>
<div class="search-form-wrap">
  <div class="local-search local-search-plugin">
  <input type="search" id="local-search-input" class="local-search-input" placeholder="Search...">
  <div id="local-search-result" class="local-search-result"></div>
</div>
</div>
    </aside>
    <div id="mask"></div>

<!-- #reward -->
<div id="reward">
  <span class="close"><i class="ri-close-line"></i></span>
  <p class="reward-p"><i class="ri-cup-line"></i>请我喝杯咖啡吧~</p>
  <div class="reward-box">
    
    <div class="reward-item">
      <img class="reward-img" src="/images/alipay.jpg">
      <span class="reward-type">支付宝</span>
    </div>
    
    
    <div class="reward-item">
      <img class="reward-img" src="/images/wechat.jpg">
      <span class="reward-type">微信</span>
    </div>
    
  </div>
</div>
    
<script src="/js/jquery-2.0.3.min.js"></script>


<script src="/js/share.js"></script>


<script src="/js/lazyload.min.js"></script>


<script>
  try {
    var typed = new Typed("#subtitle", {
      strings: ['面朝大海，春暖花开', '愿你一生努力，一生被爱', '想要的都拥有，得不到的都释怀'],
      startDelay: 0,
      typeSpeed: 200,
      loop: true,
      backSpeed: 100,
      showCursor: true
    });
  } catch (err) {
  }

</script>




<script src="/js/tocbot.min.js"></script>

<script>
  // Tocbot_v4.7.0  http://tscanlin.github.io/tocbot/
  tocbot.init({
    tocSelector: '.tocbot',
    contentSelector: '.article-entry',
    headingSelector: 'h1, h2, h3, h4, h5, h6',
    hasInnerContainers: true,
    scrollSmooth: true,
    scrollContainer: 'main',
    positionFixedSelector: '.tocbot',
    positionFixedClass: 'is-position-fixed',
    fixedSidebarOffset: 'auto',
    onClick: (e) => {
      $('.toc-link').removeClass('is-active-link');
      $(`a[href=${e.target.hash}]`).addClass('is-active-link');
      $(e.target.hash).scrollIntoView();
      return false;
    }
  });
</script>



<script src="https://cdn.jsdelivr.net/npm/jquery-modal@0.9.2/jquery.modal.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/jquery-modal@0.9.2/jquery.modal.min.css">
<script src="https://cdn.jsdelivr.net/npm/justifiedGallery@3.7.0/dist/js/jquery.justifiedGallery.min.js"></script>

<script src="/js/ayer.js"></script>



<!-- Root element of PhotoSwipe. Must have class pswp. -->
<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">

    <!-- Background of PhotoSwipe. 
         It's a separate element as animating opacity is faster than rgba(). -->
    <div class="pswp__bg"></div>

    <!-- Slides wrapper with overflow:hidden. -->
    <div class="pswp__scroll-wrap">

        <!-- Container that holds slides. 
            PhotoSwipe keeps only 3 of them in the DOM to save memory.
            Don't modify these 3 pswp__item elements, data is added later on. -->
        <div class="pswp__container">
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
        </div>

        <!-- Default (PhotoSwipeUI_Default) interface on top of sliding area. Can be changed. -->
        <div class="pswp__ui pswp__ui--hidden">

            <div class="pswp__top-bar">

                <!--  Controls are self-explanatory. Order can be changed. -->

                <div class="pswp__counter"></div>

                <button class="pswp__button pswp__button--close" title="Close (Esc)"></button>

                <button class="pswp__button pswp__button--share" style="display:none" title="Share"></button>

                <button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button>

                <button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button>

                <!-- Preloader demo http://codepen.io/dimsemenov/pen/yyBWoR -->
                <!-- element will get class pswp__preloader--active when preloader is running -->
                <div class="pswp__preloader">
                    <div class="pswp__preloader__icn">
                        <div class="pswp__preloader__cut">
                            <div class="pswp__preloader__donut"></div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">
                <div class="pswp__share-tooltip"></div>
            </div>

            <button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)">
            </button>

            <button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)">
            </button>

            <div class="pswp__caption">
                <div class="pswp__caption__center"></div>
            </div>

        </div>

    </div>

</div>

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/default-skin/default-skin.min.css">
<script src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe-ui-default.min.js"></script>

<script>
    function viewer_init() {
        let pswpElement = document.querySelectorAll('.pswp')[0];
        let $imgArr = document.querySelectorAll(('.article-entry img:not(.reward-img)'))

        $imgArr.forEach(($em, i) => {
            $em.onclick = () => {
                // slider展开状态
                // todo: 这样不好，后面改成状态
                if (document.querySelector('.left-col.show')) return
                let items = []
                $imgArr.forEach(($em2, i2) => {
                    let img = $em2.getAttribute('data-idx', i2)
                    let src = $em2.getAttribute('data-target') || $em2.getAttribute('src')
                    let title = $em2.getAttribute('alt')
                    // 获得原图尺寸
                    const image = new Image()
                    image.src = src
                    items.push({
                        src: src,
                        w: image.width || $em2.width,
                        h: image.height || $em2.height,
                        title: title
                    })
                })
                var gallery = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, items, {
                    index: parseInt(i)
                });
                gallery.init()
            }
        })
    }
    viewer_init()
</script>




<script src="/js/busuanzi-2.3.pure.min.js"></script>



<script type="text/javascript" src="https://js.users.51.la/20544303.js"></script>

    
  </div>
</body>

</html>